package com.edu.provider;

import com.edu.api.AdminApi;
import com.edu.pojo.*;
import com.edu.service.AdminService;
import com.edu.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @作者 five-five
 * @创建时间 2021/1/16
 */
@Api(tags = "Admin管理相关接口",value = "Admin管理相关接口")
@RestController
public class AdminProvider implements AdminApi {
    @Autowired
    private AdminService adminService;
    @Qualifier(value = "studentService")
    @Autowired
    private StudentService studentService;

    @ApiOperation(notes = "根据id得到用户", value = "根据id得到用户")
    @Override
    public APIResult<Admin> getById(
            @ApiParam(name = "id", value = "id",required = true)
            @RequestParam(name = "id",required = true) String id) {
        APIResult<Admin> result = new APIResult<>();
        Admin byId = adminService.getById(id);
        result.setData(byId);
        result.setState(200);
        return result;
    }

    @ApiOperation(value = "拿到所有学生",notes = "测试dubbo")
    @Override
    public APIResult<Object> stuList() {
        APIResult<Object> result = new APIResult<>();
        APIRequestPage apiRequestPage = new APIRequestPage();
        apiRequestPage.setLimit(20);
        apiRequestPage.setPageNo(1);
        List<Student> all = studentService.getAll(new APIRequest(apiRequestPage));
//        List<Student> all = studentService.getAll(null);
        result.setData(all);
        result.setState(200);
        result.setMessage("dubbo调用成功");
        return result;
    }
}
